﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.Statistics;
using MINERP.MODEL.FoundationModel;
using MINERP.COM;
using MINERP.ComControls.Extension;

namespace MINERP.Statistics
{
    public partial class FrmPerformanceByPhotoSpec : Form
    {
        private PerformanceBLL _bll ;

        public FrmPerformanceByPhotoSpec()
        {
            InitializeComponent();
            _bll = new PerformanceBLL();
            gvep.ShowRowIndicator(50);
        }

        private static FrmPerformanceByPhotoSpec _instance;

        public static FrmPerformanceByPhotoSpec GetInstance
        {
            get
            {
                if (_instance == null || _instance.Disposing)
                {
                    _instance = new FrmPerformanceByPhotoSpec();
                }

                return _instance;
            }
        }

        private void FrmPerformanceByPhotoSpec_Load(object sender, EventArgs e)
        {
            BandingGroup(_bll.GetAllGroup());
            dtStart.DateTime = DateTime.Now.Date;
            dtEnd.DateTime = DateTime.Now.Date;
        }

        void BandingGroup(List<Tb_WorkerGroup_Info> list)
        {
            cmbGroup.DisplayMember = "GroupName";
            cmbGroup.ValueMember = "GroupId";
            cmbGroup.DataSource = list;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //saveFileDialog1.FileName = cmbGroup.Text+"组的员工业绩.xls";

                string saveDir = saveFileDialog1.FileName;
                if (!string.IsNullOrEmpty(saveDir))
                {
                    gcep.ExportToExcel(this, saveDir);
                    //gvep.ExportToXls(saveDir);
                    //MessageBox.Show("导出成功!");
                }
            }
        }

        private void cmbGroup_SelectionChangeCommitted(object sender, EventArgs e)
        {
            int GroupId = ((Tb_WorkerGroup_Info)this.cmbGroup.SelectedItem).GroupId;
            BindWorkerList(GroupId);
        }
        private void BindWorkerList(int GroupId)
        {
            List<UserInfo> userList = new List<UserInfo>();
            if (GroupId > 0)
            {
                userList = _bll.GetUserByGroupId(GroupId);
            }
            cmkUser.Properties.DataSource = userList;
            cmkUser.Properties.DisplayMember = "UserName";
            cmkUser.Properties.ValueMember = "UserID";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            BindEP();
        }

        private void BindEP()
        {
            List<UserInfo> userList = cmkUser.Properties.DataSource as List<UserInfo>;
            gcep.DataSource= _bll.GetEPByPhotoSpec(userList, dtStart.DateTime, dtEnd.DateTime.Date);
            gcep.RefreshDataSource();
            
        }

        private void FrmPerformanceByPhotoSpec_FormClosing(object sender, FormClosingEventArgs e)
        {
            _instance = null;
        }
    }
}
